def getPrimes(limit):
    primes = []
    numbers = [True] * limit
    for i in range(2, limit):
        if numbers[i]:
            primes.append(i)
            for n in range(i ** 2, limit, i):
                numbers[n] = False
    return primes



valid = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
v=[]
a=input()
a_sp= a.split()
n=0
if len(a_sp) != 3:
    print("Wrong input")
else:
    for i in a_sp:
        for j in valid:
            if i == j:
                n+=1
if n == 3:
    for i in a_sp:
        if i=="zero":
            v.append('0')
        if i=="one":
            v.append('1')
        if i=="two":
            v.append('2')
        if i=="three":
            v.append('3')
        if i=="four":
            v.append('4')
        if i=="five":
            v.append('5')
        if i=="six":
            v.append('6')
        if i=="seven":
            v.append('7')
        if i=="eight":
            v.append('8')
        if i=="nine":
            v.append('9')
else:
    print("Wrong input")

number=int(''.join(str(i) for i in v))

primes = getPrimes(number + 100)


maxDist = 99999999

numb = 0


for p in primes:
    if abs(number - p) < maxDist:
        maxDist = abs(number - p)
        numb = p

print(numb)
